#include <iostream>
#include <vector>

using namespace std;

/*
3 3
7 6
255 255 0 0 0 255
0 255 255 255 255 0
0 255 255 255 255 255
0 255 255 255 255 0
0 255 255 255 0 0
255 255 255 255 255 255
0 0 0 0 0 255
*/

// 腐蚀
int erode(vector<vector<int> > src, int H, int W, int r, int c, int N, int M)
{
    // 储存最小值
    int min = src[r][c];

    for (int rr = r - N / 2; rr <= r + N / 2; rr++)
    {
        if (rr <0 || rr >= H)
            return 0;
        for (int cc = c - M / 2; cc <= c + M / 2; cc++)
        {  
            if (cc <0 || cc >= W)
                return 0;

            if(min > src[rr][cc])
                min = src[rr][cc];
        }
    }

    return min;
}

// 膨胀
int inflate(vector<vector<int> > src, int H, int W, int r, int c, int N, int M)
{
    // 储存最大值
    int max = src[r][c];

    for (int rr = r - N / 2; rr <= r + N / 2; rr++)
    {
        if (rr <0 || rr >= H)
            continue;
        for (int cc = c - M / 2; cc <= c + M / 2; cc++)
        {  
            if (cc <0 || cc >= W)
                continue;

            if(max < src[rr][cc])
                max = src[rr][cc];
        }
    }

    return max;
}
int main()
{
    // 结构元 高、宽
    int N, M;
    cin >> N;
    cin >> M;

    // 图片的 高、宽
    int H, W;
    cin >> H;
    cin >> W;

    // 存储图片
    vector<vector<int> > src;
    vector<int> temp;

    for (int r = 0; r < H; r++)
    {
        for (int c = 0; c < W; c++)
        {
            int num;
            cin >> num;
            temp.push_back(num);
        }
        src.push_back(temp);
        temp.clear();
    }
    
    // 存储腐蚀之后的图片
    vector<vector<int> > src_erode;

    for (int r = 0; r < H; r++)
    {
        for (int c = 0; c < W; c++)
        {
            int num = erode(src, H, W, r, c, N, M);
            temp.push_back(num);
        }
        src_erode.push_back(temp);
        temp.clear();
    }

    // 存储膨胀之后的图片
    vector<vector<int> > src_inflate;

    for (int r = 0; r < H; r++)
    {
        for (int c = 0; c < W; c++)
        {
            int num = inflate(src_erode, H, W, r, c, N, M);
            temp.push_back(num);
        }
        src_inflate.push_back(temp);
        temp.clear();
    }

    for (int r = 0; r < H; r++)
    {
        for (int c = 0; c < W; c++)
        {
            if (c == W-1)
            {
                cout << src_inflate[r][c];
            }
            else{
                cout << src_inflate[r][c] << " ";
            }
        }
        cout << endl;
    }
    return 0;
}